﻿using System;
using UniRx;
using UniRx.Triggers;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace Studio
{
	// Token: 0x020005D3 RID: 1491
	[RequireComponent(typeof(TextSlideEffect))]
	public class TextSlideEffectCtrl : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IEventSystemHandler
	{
		// Token: 0x06002610 RID: 9744 RVA: 0x000DFE98 File Offset: 0x000DE098
		private void MoveText()
		{
			float x = this.transBase.sizeDelta.x;
			float preferredWidth = this.text.preferredWidth;
			if (x >= preferredWidth)
			{
				return;
			}
			float num = this.textSlideEffect.subPos;
			if (num > preferredWidth)
			{
				num -= preferredWidth + x;
			}
			num += this.speed * Time.deltaTime;
			this.textSlideEffect.subPos = num;
		}

		// Token: 0x06002611 RID: 9745 RVA: 0x000DFF04 File Offset: 0x000DE104
		private void Check()
		{
			float x = this.transBase.sizeDelta.x;
			float preferredWidth = this.text.preferredWidth;
			if (x >= preferredWidth)
			{
				ObservableLateUpdateTrigger component = base.GetComponent<ObservableLateUpdateTrigger>();
				if (component != null)
				{
					UnityEngine.Object.Destroy(component);
				}
				UnityEngine.Object.Destroy(this);
				UnityEngine.Object.Destroy(this.textSlideEffect);
				return;
			}
			this.text.alignment = TextAnchor.MiddleLeft;
			this.text.horizontalOverflow = HorizontalWrapMode.Overflow;
			this.text.raycastTarget = true;
			this.AddFunc();
		}

		// Token: 0x06002612 RID: 9746 RVA: 0x000DFF90 File Offset: 0x000DE190
		private void AddFunc()
		{
			(from _ in this.UpdateAsObservable()
			where this.isPlay
			select _).Subscribe(delegate(Unit _)
			{
				this.MoveText();
			}).AddTo(this);
		}

		// Token: 0x06002613 RID: 9747 RVA: 0x000DFFC4 File Offset: 0x000DE1C4
		private void Start()
		{
			if (this.assist)
			{
				this.LateUpdateAsObservable().First<Unit>().Subscribe(delegate(Unit _)
				{
					this.Check();
				}).AddTo(this);
			}
			else
			{
				this.AddFunc();
			}
		}

		// Token: 0x06002614 RID: 9748 RVA: 0x000E0000 File Offset: 0x000DE200
		public void OnPointerEnter(PointerEventData eventData)
		{
			this.isPlay = true;
		}

		// Token: 0x06002615 RID: 9749 RVA: 0x000E000C File Offset: 0x000DE20C
		public void OnPointerExit(PointerEventData eventData)
		{
			this.isPlay = false;
			this.textSlideEffect.subPos = 0f;
		}

		// Token: 0x0400263F RID: 9791
		[SerializeField]
		private TextSlideEffect textSlideEffect;

		// Token: 0x04002640 RID: 9792
		[SerializeField]
		private RectTransform transBase;

		// Token: 0x04002641 RID: 9793
		[SerializeField]
		private Text text;

		// Token: 0x04002642 RID: 9794
		public float speed = 50f;

		// Token: 0x04002643 RID: 9795
		public bool assist;

		// Token: 0x04002644 RID: 9796
		private bool isPlay;
	}
}
